import { createPersistedState } from "pinia-plugin-persistedstate";

import * as Pinia from "pinia";

export { Pinia };

const LOCAL_PREFIX = "__LOCAL__";

export function setupPinia(app: any) {
  const pinia = Pinia.createPinia();
  pinia.use(
    createPersistedState({
      key: (id) => `${LOCAL_PREFIX}${id}`,
      storage: {
        getItem: (key) => uni.getStorageSync(key),
        setItem: (key, value) => uni.setStorageSync(key, value),
      },
    }),
  );
  app.use(pinia);
}
